FROM ros:noetic-ros-base

# 替换为国内源 
RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' /etc/apt/sources.list
RUN sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

RUN apt-get update \
 && apt-get install -y --no-install-recommends git && apt-get clean && rm -rf /var/lib/apt/lists/*

# RUN apt-get update && apt-get install -y --no-install-recommends rsync \
#  && apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /root

RUN mkdir -p /root/catkin_ws/src

WORKDIR /root/catkin_ws/src 
RUN git clone https://github.com/MIT-SPARK/Kimera-Multi.git kimera_multi; 

COPY dependencies.sh kimera_multi/install/dependencies.sh
COPY kimera_multi.repos kimera_multi/kimera_multi.repos

RUN /bin/bash kimera_multi/install/dependencies.sh; 
RUN apt-get update && apt-get install -y --no-install-recommends python3-vcstool \
 && apt-get clean && rm -rf /var/lib/apt/lists/*

RUN    vcs import . --input kimera_multi/kimera_multi.repos --recursive

RUN apt-get update \
 && apt-get install -y --no-install-recommends \
 && apt-get install -y --no-install-recommends git wget nano build-essential libgoogle-glog-dev automake libtool m4 automake \
                                               python3-wstool python3-catkin-tools \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

RUN    cd ..; \
    catkin config -a  --extend /opt/ros/noetic --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo -DGTSAM_TANGENT_PREINTEGRATION=OFF -DGTSAM_BUILD_WITH_MARCH_NATIVE=OFF -DOPENGV_BUILD_WITH_MARCH_NATIVE=OFF; \
    catkin build --continue -s -j 16; 

RUN sed -i "6i source \"/root/catkin_ws/devel/setup.bash\"" /ros_entrypoint.sh

ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["bash"]